﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Manager.DataAccess
{
    public partial class DataDepartment
    {
        public int MaTang { get; set; }
        public string TenTang { get; set; }
        public int ViTri { get; set; }

        
        SqlCommand cmd;
        static SqlConnection conn;

        static DataDepartment()
        {
            conn = AccessData.GetConnect();
        }

        public void Insert(DataDepartment dt)
        {
            cmd = new SqlCommand("SP_Tang_Insert", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaTang", SqlDbType.Int).Value = dt.MaTang;
            cmd.Parameters.Add("@TenTang", SqlDbType.NVarChar).Value = dt.TenTang;
            cmd.Parameters.Add("@ViTri", SqlDbType.Int).Value = dt.ViTri;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        public void Update(DataDepartment dt)
        {
            cmd = new SqlCommand("SP_Tang_Update", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaTang", SqlDbType.Int).Value = dt.MaTang;
            cmd.Parameters.Add("@TenTang", SqlDbType.NVarChar).Value = dt.TenTang;
            cmd.Parameters.Add("@ViTri", SqlDbType.Int).Value = dt.ViTri;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        public void Delete(DataDepartment dt)
        {
            cmd = new SqlCommand("SP_Tang_Delete", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaTang", SqlDbType.Int).Value = dt.MaTang;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            conn.Close();
        }
        public DataTable GetAll()
        {
            SqlDataAdapter adapter = new SqlDataAdapter("SP_Tang_SelectAll", conn);
            DataTable table = new DataTable();
            adapter.Fill(table);
            adapter.Dispose();
            return table;
        }
        public DataTable GetByID(object MaTang)
        {
            cmd = new SqlCommand("SP_Tang_GetByID", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaTang", SqlDbType.Int).Value = int.Parse(MaTang.ToString());
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            adapter.Fill(table);
            cmd.Dispose();
            adapter.Dispose();
            return table;
        }
        public DataTable GetAllPhongByMaTang(object MaTang)
        {
            cmd = new SqlCommand("SP_Tang_SelectAllPhongByMaTang", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaTang", SqlDbType.Int).Value = int.Parse(MaTang.ToString());
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            adapter.Fill(table);
            cmd.Dispose();
            adapter.Dispose();
            return table;
        }
    }
}
